//
// Created by 谢哲 on 2021/5/13.
//

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;

    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i=0; i<n; ++i) {
        int a;
        cin >> a;
        pq.push(a);
    }

    int ans = 0;
    for (int i = 0; i < n-1; ++i) {
        int p1 = pq.top();
        pq.pop();
        int p2 = pq.top();
        pq.pop();
        ans += p1 + p2;
        pq.push(p1 + p2);
    }

    cout << ans;

    return 0;
}
